Creating an XSLT to get any Image [parametrised] from any Page
As the title suggest, I am trying to create an XSLT to be used in a macro, that the user can give it two parameters: basically the page you want to find the image from, and also the image name. The XSLT seems good, but I am getting an integer exception at the $thisImage parameter in GetMedia. Anyone can suggest a better way / or a functioning way please?
Creating an XSLT to get any Image [parametrised] from any Page
As the title suggest, I am trying to create an XSLT to be used in a macro, that the user can give it two parameters: basically the page you want to find the image from, and also the image name. The XSLT seems good, but I am getting an integer exception at the $thisImage parameter in GetMedia. Anyone can suggest a better way / or a functioning way please?
Thanks beforehand!
Hi Matthew,
I'm assuming you are using Umbraco 4.5.x
You'll want to change the thisImage variable to the following:
The data element is from the old 4.0.x schema
Many thanks
Matt
Ooops, you'll also want to change your src and alt selectors aswell
Matt
Hi Matthew,
I could be mistaken, but I don't think you can use the xsl:param to take custom parameters.
would be how I pull in settable paramaeters - and don't forget to define them on the macro too
/Josh
Hi Matthew,
A couple of pointers for you:
1) As Josh says, you have only one way of assigning values to <xsl:param> elements from the outside, which is
to select content for them from the macro document Umbraco provides. So if your macro defines the parameters
"searchPage" and "imageName", they're accessible as child nodes of the macro element:
(You can use either xsl:param or xsl:variable here - makes no difference)
2) About selecting the nodes you need (I don't know if you're using version 4.0 or 4.5, so I'll
provide some "Universal Binary" code here.) - you need to do this:
Selecting the "rootNode":
- Use *[@level = 1] to have it work in both 4.0 and 4.5:
Selecting "thisPage":
- It's a little bit confusing what you're actually sending into this - I'll assume an @id (contentPicker on macro);
then you'd do this:
Selecting "thisImage":
- I assume the image is a property on $thisPage:
Yay - so far, so good. Now, generating output:
3) First make sure you actually have a media id; then be sure to cache the GetMedia() result in a variable.
Then, go generate the <img> tag in one swoop using Attribute Value Templates (curly braces):
Important: If you're using version 4.5 (and not 4.5.1) you need to replace $imageData/* with $imageData//* because of a nasty bug...
/Chriztian
All of it, just for reference:
/Chriztian
thanks alot for your reply Chriztian!
that helped me alot.
I have set up searchPage as a content picker (or should I use it as a text?) I have set up imageName as text. I am calling it like:
There are no errors, but nothing is being shown. any idea how I can debug please?
did the trick ;)
Hi Matthew,
Yeah, you caught me - I forgot to "universalize" that one, but crossed my fingers and hoped you were using 4.5+ :-)
Glad you got it, though ;-)
/Chriztian
is working on a reply...